import { ref,reactive } from "vue";
import { defineStore } from "pinia";
import { getHomeData,getHomeGoods } from "@/api/homeApi.js";
// import { getHomeData } from "@/api/homeApi.js";
export const useHomeStore = defineStore("home", () => {
  const homeData = reactive({
    // 轮播图
    bannerList: [
      {
        id: 1,
        img: "https://img2.baidu.com/it/u=3819265764,375522631&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
      },
      {
        id: 2,
        img: "https://img2.baidu.com/it/u=3819265764,375522631&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
      },
      {
        id: 3,
        img: "https://img2.baidu.com/it/u=3819265764,375522631&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500",
      },
    ],
    title: "首页",
    count: 0,
  });
  // 展开收起
  const isShow = ref(false)
//   修改title
  const changeTitle = (title) => {
    homeData.title = title   
  }
//   count加1
  const addCount = () => {
    homeData.count++
  }
  //修改isShow
  const changeIsShow = () => {
    isShow.value = !isShow.value
    console.log(isShow.value)
  }
  // 从接口获取首页数据
  const fetchHomeData = async () => {
    const res = await getHomeGoods();
    console.log(res.data);
  }
  



  return {
    homeData,
    changeTitle,
    addCount,
    fetchHomeData,
    isShow,
    changeIsShow
  }
})